package study.nosql.redis.service.key_event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

@Slf4j
//@Component
public class _2_KeyExpiredListener extends KeyExpirationEventMessageListener {

    public _2_KeyExpiredListener(RedisMessageListenerContainer container) {
        super(container);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        //频道
        byte[] channel = message.getChannel();
        //消息
        byte[] body = message.getBody();
        String key = new String(body);

        log.info(">>>>>> channel= {}, key= {}", new String(channel), key);
    }
}
